<?php
/**
 * 中介者模式----设计模式
 * Created by Jason.
 * User: Administrator
 * Date: 2019/12/7 0007
 * Time: 下午 5:28
 */

namespace app\index\service;


use app\index\interfaces\MediatorInterface;

/**
 * Mediator 是用于访设计模式的中介者模式的实体
 *
 * 本示例中，我用中介者模式做了一个 “Hello World” 的响应
 */
class Mediator implements MediatorInterface
{
    private $server;

    private $database;

    private $client;

    public function __construct(DataBase $dataBase, Client $client, Server $server)
    {
        $this->server   = $server;
        $this->database = $dataBase;
        $this->client   = $client;

        $this->server->setMediator($this);
        $this->database->setMediator($this);
        $this->client->setMediator($this);
    }

    public function makeRequest()
    {
        $this->server->process();
    }

    public function sendResponse($content)
    {

        $this->client->output($content);
    }

    public function queryDb():string
    {
        return $this->database->getData();
    }
}